package dao.impl;

import dao.ProvinceDao;
import entity.Province;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import util.C3P0Util;

import java.sql.SQLException;
import java.util.List;

public class ProvinceDaoImpl implements ProvinceDao{

	@Override
	public List<Province> getAllProvinceList() {
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());
		try {
			return qr.query("select * from province", 
					new BeanListHandler<Province>(Province.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	@Override
	public Province getProvinceByProId(Integer ProId) {
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());	
		String sql="select * from province where id = ? ";
		Province Province=null;
		try {
			Province = qr.query(sql, ProId, new BeanHandler<Province>(Province.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}	
		return Province;
	}


}
